﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;

namespace TfsBugger.Util.Ui
{
    public static class UserControlExtensions
    {
        public static T FindFirstAncestorOfType<T>(this FrameworkElement elem)
            where T : FrameworkElement
        {
            T anc = default(T);
            FrameworkElement cur = elem;
            while (true)
            {
                FrameworkElement par = cur.Parent as FrameworkElement;
                if (null == par)
                    break;

                anc = par as T;
                if (null != anc)
                    break;

                cur = par;
            }

            return anc;
        }
    }
}
